package org.jrfe.gfx.g2d.shapes;

import org.jrfe.JRFE;
import org.jrfe.gfx.Vertex;
import org.jrfe.math.Vector2f;


public class Quad extends AbstractShape{

	protected float xExtend;
	protected float yExtend;
	
	public Quad(Vector2f loc,float xExtend,float yExtend) {
		super(4,loc,0,new Vector2f(),JRFE.PrimitiveTypes.QUADS);
		this.xExtend = xExtend;
		this.yExtend = yExtend;
				
		Vertex v = new  Vertex();
		v.a = 1;
		v.r = 1;
		v.b = 1;
		v.g = 1;
		
		v.x = xExtend;
		v.y = yExtend;
		v.s = 1;
		v.t = 0;
		getBatch().update(0, v);
		
		v.x = -xExtend;
		v.y = yExtend;
		v.s = 0;
		v.t = 0;
		getBatch().update(1, v);
		
		v.x = -xExtend;
		v.y = -yExtend;
		v.s = 0;
		v.t = 1;
		getBatch().update(2, v);
		
		v.x = xExtend;
		v.y = -yExtend;
		v.s = 1;
		v.t = 1;
		getBatch().update(3, v);
				
	}	
	
	@Override
	public void updateTextureCords() {
	
		if(mappedTexture != null){
			getBatch().getTexCords().put(0, mappedTexture.getMapMaxX());
			getBatch().getTexCords().put(1, mappedTexture.getMapMinY());
		
			getBatch().getTexCords().put(2, mappedTexture.getMapMinX());
			getBatch().getTexCords().put(3, mappedTexture.getMapMinY());
		
			getBatch().getTexCords().put(4, mappedTexture.getMapMinX());
			getBatch().getTexCords().put(5, mappedTexture.getMapMaxY());
		
			getBatch().getTexCords().put(6, mappedTexture.getMapMaxX());
			getBatch().getTexCords().put(7, mappedTexture.getMapMaxY());
		}
	}
	
	public float getXExtend() {
		return xExtend;
	}
	
	public float getYExtend() {
		return yExtend;
	}
	
}
